package com.zzl.study.auth.enums;

import com.zzl.study.auth.domain.dto.Options;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author: zhangzl
 * @date: 2023/12/7 20:20
 * @version: 1.0
 * @description: 授权模式枚举
 * @see org.springframework.security.oauth2.core.AuthorizationGrantType
 */
@Getter
public enum AuthorizationGrantType {

    /**
     * 授权码模式
     */
    AUTHORIZATION_CODE("授权码模式", "authorization_code"),

    /**
     * token刷新
     */
    REFRESH_TOKEN("token刷新", "refresh_token"),

    /**
     * 客户端凭证
     */
    CLIENT_CREDENTIALS("客户端凭证", "client_credentials");

    /**
     * 描述
     */
    private final String name;

    /**
     * 值
     */
    private final String value;

    AuthorizationGrantType(String name, String value) {
        this.name = name;
        this.value = value;
    }

    /**
     * 授权模式枚举转下拉框选项集合
     *
     * @return 下拉框选项集合
     */
    public static List<Options> toList() {
        return Arrays.stream(AuthorizationGrantType.values()).map(e -> new Options(e.getName(), e.getValue())).toList();
    }

}
